package edu.mobbuzz.main;

import java.io.IOException;

import edu.mobbuzz.messaging.Messaging;
import edu.mobbuzz.rss.reader.FeedReader;

public class RSSPushServer {
	private Messaging messaging;
	private FeedReader feed; 
	
	public RSSPushServer(){
		messaging = new Messaging();
	}
	
	public static void main(String[] args){
		RSSPushServer app = new RSSPushServer();
		app.connectToServer();
	}
	
	public void connectToServer() {
        Thread t = new Thread() {
			public void run() {
				try {
					messaging.connect("http://mobbuzzworld.s155.eatj.com","news","mobbuzz.com","mobbuzz08",0);
					//messaging.connect("127.0.0.1","news","mobbuzz.com","mobbuzz08",0);
				} catch (IOException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};
		t.start();

        do{
        	
        }while(messaging.getState()!= messaging.ONLINE);
        
        if(messaging.getState()==messaging.ONLINE){
        	try {
        		Schedular _schedular = new Schedular();
        		_schedular.setMessaging(messaging);
        		_schedular.run();
        		//messaging.sendRssResponse("", "");
			} catch (Exception e) {
				e.printStackTrace();
			}
        } 
    }
}
